﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using Confucius.utils;

namespace Confucius.entity
{
    /// <summary>
    /// Author:Liangchuan Gu
    /// date:2012-04-08
    /// </summary>
    public class Item
    {
        private string itemID;

        public string ItemID
        {
            get { return itemID; }
            set { itemID = value; }
        }

        private string title;

        public string Title
        {
            get { return title; }
            set { title = value; }
        }

        private string displayText;

        public string DisplayText
        {
            get { return displayText; }
            set { displayText = value; }
        }

        private string iconID;

        public string IconID
        {
            get 
            {
                if (iconID == null)
                {
                    return itemID;
                }
                else
                {
                    return iconID;
                }
            }
            set { iconID = value; }
        }

        private string containedMediaID;

        public string ContainedMediaID
        {
            get { return containedMediaID; }
            set { containedMediaID = value; }
        }

        private string pickable;

        public string Pickable
        {
            get { return pickable; }
            set { pickable = value; }
        }

        private float lat;

        public float Lat
        {
            get { return lat; }
            set { lat = value; }
        }

        private float lng;

        public float Lng
        {
            get { return lng; }
            set { lng = value; }
        }

        private string status;

        public string Status
        {
            get { return status; }
            set { status = value; }
        }

        public const string NOT_PICKABLE = "f";
        public const string PICKABLE = "t";
        public const string PICKED = "p";

        public string IconUri
        {
            get
            {
                string[] idString = iconID.Split('.');
                if (idString.Length < 2)
                {
                    if (IsolatedStorageSettings.ApplicationSettings.Contains(Constants.CURRENT_GAMEID))
                    {
                        string gameID = (string)IsolatedStorageSettings.ApplicationSettings[Constants.CURRENT_GAMEID];
                        return "/Confucius;component/assets/gameFiles/" + gameID + "/" + iconID + ".png";
                    }
                    else
                        return "/Confucius;component/assets/images/item.png";
                }
                else
                {
                    if (IsolatedStorageSettings.ApplicationSettings.Contains(Constants.CURRENT_GAMEID))
                    {
                        string gameID = (string)IsolatedStorageSettings.ApplicationSettings[Constants.CURRENT_GAMEID];
                        return "/Confucius;component/assets/gameFiles/" + gameID + "/" + iconID;
                    }
                    else
                        return "/Confucius;component/assets/images/item.png";
                }
            }
        }

        public Visibility ListVisibility
        {
            get
            {
                if (status.Equals(PICKED))
                    return Visibility.Visible;
                else
                    return Visibility.Collapsed;
            }
        }

        public Visibility PickableListVisibility
        {
            get
            {
                if (status.Equals(PICKABLE))
                    return Visibility.Visible;
                else
                    return Visibility.Collapsed;
            }
        }

        public string StatusToText
        {
            get
            {
                if (status.Equals(PICKABLE))
                    return "Pickable  ";
                else if (status.Equals(NOT_PICKABLE))
                    return "Not Pickable  ";
                else
                    return "Picked  ";
            }
        }

        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return false;
            }

            // If parameter cannot be cast to this class return false.
            Item p = obj as Item;
            if ((System.Object)p == null)
            {
                return false;
            }

            // Return true if the fields match:
            return (itemID == p.itemID) && (status == p.status);
        }

        public override int GetHashCode()
        {
            return itemID.GetHashCode() * (status.GetHashCode());
        }
    }
}
